<?php
namespace Home\Controller;
use Think\Controller;
class ArtController extends CommonController {
    public function art(){
    	$art = M('Art');
    	$where['art_id'] = I('art_id');
        $art->where($where)->setInc('art_hits',1);
    	$res = $art->where($where)->find();
    	$this->assign($res);
        // var_dump($rs);exit;
    	$this->display();
    }
    public function artlist(){
        $art = M('Art');
        $cat = M('Cat');
        $where['cat_id'] = I('cat_id');
        $cat = $cat->where($where)->find();
        $res = $art->where($where)->select();

        $count      = $art->where($where)->count();// 查询满足要求的总记录数
        $Page       = new \Think\Page($count,5);// 实例化分页类 传入总记录数和每页显示的记录数(25)
        $Page->setConfig('first','首页');
        $Page->setConfig('last','尾页');
        $Page->setConfig('prev','上一页');
        $Page->setConfig('next','下一页');
        $show       = $Page->show();// 分页显示输出
        // 进行分页数据查询 注意limit方法的参数要使用Page类的属性
        $list = $art->where($where)->order('art_id')->limit($Page->firstRow.','.$Page->listRows)->select();
        $this->assign('list',$list);// 赋值数据集
        $this->assign('page',$show);// 赋值分页输出
        $this->assign($cat);
        //var_dump($list);exit;
        // var_dump($cat);exit;
        $this->display();
    }
    public function do_like(){
        
        $id=intval($_POST['art_id']);//posts表中id
        
        $posts_model=M("Art");
        
        $can_like=sp_check_user_action("posts$id",1);
        
        if($can_like){
            $posts_model->save(array("art_id"=>$id,"art_like"=>array("exp","art_like+1")));
            $rs['status'] = 200;
        }else{
            $rs['status'] = 0;
        }
        $this->ajaxReturn($rs);die;
    }
    public function about(){
    	$this->display();
    }
}